| @@ -8,11 +8,11 @@ module AgentHelper | ||
| 8 | 8 |  | 
| 9 | 9 | def scenario_links(agent) | 
| 10 | 10 |      agent.scenarios.map { |scenario| | 
| 11 | - link_to(scenario.name, scenario, class: "label label-info") | |
| 11 | + link_to(scenario.name, scenario, class: "label", style: style_colors(scenario)) | |
| 12 | 12 |      }.join(" ").html_safe | 
| 13 | 13 | end | 
| 14 | 14 |  | 
| 15 | 15 | def agent_show_class(agent) | 
| 16 | 16 | agent.short_type.underscore.dasherize | 
| 17 | 17 | end | 
| 18 | -end | |
| 18 | +end | 
| @@ -0,0 +1,10 @@ | ||
| 1 | +module ScenarioHelper | |
| 2 | + | |
| 3 | + def style_colors(scenario) | |
| 4 | +    colors = { | |
| 5 | + color: scenario.tag_fg_color, | |
| 6 | + background_color: scenario.tag_bg_color | |
| 7 | +    }.map { |key, value| "#{key.to_s.dasherize}:#{value}" }.join(';') | |
| 8 | + end | |
| 9 | + | |
| 10 | +end | 
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | class Scenario < ActiveRecord::Base | 
| 2 | 2 | include HasGuid | 
| 3 | 3 |  | 
| 4 | - attr_accessible :name, :agent_ids, :description, :public, :source_url | |
| 4 | + attr_accessible :name, :agent_ids, :description, :public, :source_url, :tag_fg_color, :tag_bg_color | |
| 5 | 5 |  | 
| 6 | 6 | belongs_to :user, :counter_cache => :scenario_count, :inverse_of => :scenarios | 
| 7 | 7 | has_many :scenario_memberships, :dependent => :destroy, :inverse_of => :scenario | 
| @@ -32,7 +32,7 @@ | ||
| 32 | 32 |  | 
| 33 | 33 | <% agent.scenarios.each do |scenario| %> | 
| 34 | 34 | <li> | 
| 35 | -        <%= link_to "<span class='color-warning glyphicon glyphicon-remove-circle'></span> Remove from <span class='scenario label label-info'>#{h scenario.name}</span>".html_safe, leave_scenario_agent_path(agent, :scenario_id => scenario.to_param, :return => returnTo), method: :put, :tabindex => "-1" %> | |
| 35 | +        <%= link_to "<span class='color-warning glyphicon glyphicon-remove-circle'></span> Remove from <span class='scenario label' style='#{style_colors(scenario)}'>#{h scenario.name}</span>".html_safe, leave_scenario_agent_path(agent, :scenario_id => scenario.to_param, :return => returnTo), method: :put, :tabindex => "-1" %> | |
| 36 | 36 | </li> | 
| 37 | 37 | <% end %> | 
| 38 | 38 | <% end %> | 
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | <div class="alert alert-warning"> | 
| 14 | 14 | <span class='glyphicon glyphicon-warning-sign'></span> | 
| 15 | 15 | This Scenario already exists in your system. The import will update your existing | 
| 16 | - <span class='label label-info scenario'><%= @scenario_import.existing_scenario.name %></span> Scenario's title | |
| 16 | + <span class='label scenario' style="<%= style_colors(@scenario_import.existing_scenario) %>"><%= @scenario_import.existing_scenario.name %></span> Scenario's title | |
| 17 | 17 | and | 
| 18 | 18 | description. Below you can customize how the individual agents get updated. | 
| 19 | 19 | </div> | 
| @@ -15,6 +15,18 @@ | ||
| 15 | 15 | <%= f.text_field :name, :class => 'form-control', :placeholder => "Name your Scenario" %> | 
| 16 | 16 | </div> | 
| 17 | 17 | </div> | 
| 18 | + <div class="col-md-2"> | |
| 19 | + <div class="form-group"> | |
| 20 | + <%= f.label :tag_bg_color %> | |
| 21 | + <%= f.color_field :tag_bg_color, :class => 'form-control', :placeholder => "#FFFFFF" %> | |
| 22 | + </div> | |
| 23 | + </div> | |
| 24 | + <div class="col-md-2"> | |
| 25 | + <div class="form-group"> | |
| 26 | + <%= f.label :tag_fg_color %> | |
| 27 | + <%= f.color_field :tag_fg_color, :class => 'form-control', :placeholder => "#000000" %> | |
| 28 | + </div> | |
| 29 | + </div> | |
| 18 | 30 | </div> | 
| 19 | 31 |  | 
| 20 | 32 | <div class="row"> | 
| @@ -54,4 +66,4 @@ | ||
| 54 | 66 | </div> | 
| 55 | 67 | </div> | 
| 56 | 68 | </div> | 
| 57 | -<% end %> | |
| 69 | +<% end %> | 
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | <% @scenarios.each do |scenario| %> | 
| 22 | 22 | <tr> | 
| 23 | 23 | <td> | 
| 24 | + <span class="label" style="<%= style_colors(scenario) %>" title="Tag"><i class="glyphicon glyphicon-font"></i></span> | |
| 24 | 25 | <%= link_to(scenario.name, scenario) %> | 
| 25 | 26 | </td> | 
| 26 | 27 | <td><%= link_to pluralize(scenario.agents.count, "agent"), scenario %></td> | 
| @@ -47,4 +48,4 @@ | ||
| 47 | 48 | </div> | 
| 48 | 49 | </div> | 
| 49 | 50 | </div> | 
| 50 | -</div> | |
| 51 | +</div> | 
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | <div class='row'> | 
| 3 | 3 | <div class='col-md-12'> | 
| 4 | 4 | <div class="page-header"> | 
| 5 | - <h2>Share <span class='label label-info scenario'><%= @scenario.name %></span> with the world</h2> | |
| 5 | + <h2>Share <span class='label scenario' style="<%= style_colors(@scenario) %>"><%= @scenario.name %></span> with the world</h2> | |
| 6 | 6 | </div> | 
| 7 | 7 |  | 
| 8 | 8 | <p> | 
| @@ -30,4 +30,4 @@ | ||
| 30 | 30 | </div> | 
| 31 | 31 | </div> | 
| 32 | 32 | </div> | 
| 33 | -</div> | |
| 33 | +</div> | 
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | <div class='row'> | 
| 3 | 3 | <div class='col-md-12'> | 
| 4 | 4 | <div class="page-header"> | 
| 5 | - <h2><span class='label label-info scenario'><%= @scenario.name %></span> <%= "Public" if @scenario.public? %> Scenario</h2> | |
| 5 | + <h2><span class='label scenario' style="<%= style_colors(@scenario) %>"><%= @scenario.name %></span> <%= "Public" if @scenario.public? %> Scenario</h2> | |
| 6 | 6 | </div> | 
| 7 | 7 |  | 
| 8 | 8 | <% if @scenario.description.present? %> | 
| @@ -0,0 +1,6 @@ | ||
| 1 | +class AddTagColorToScenarios < ActiveRecord::Migration | |
| 2 | + def change | |
| 3 | + add_column :scenarios, :tag_bg_color, :string, default: '#5bc0de' | |
| 4 | + add_column :scenarios, :tag_fg_color, :string, default: '#ffffff' | |
| 5 | + end | |
| 6 | +end | 
| @@ -111,6 +111,8 @@ ActiveRecord::Schema.define(version: 20140605032822) do | ||
| 111 | 111 | t.boolean "public", default: false, null: false | 
| 112 | 112 | t.string "guid", null: false | 
| 113 | 113 | t.string "source_url" | 
| 114 | + t.string "tag_bg_color", default: "#5bc0de" | |
| 115 | + t.string "tag_fg_color", default: "#ffffff" | |
| 114 | 116 | end | 
| 115 | 117 |  | 
| 116 | 118 | add_index "scenarios", ["user_id", "guid"], name: "index_scenarios_on_user_id_and_guid", unique: true, using: :btree | 
| @@ -0,0 +1,12 @@ | ||
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe ScenarioHelper do | |
| 4 | + | |
| 5 | + describe '#style_colors' do | |
| 6 | + it 'returns a css style-formated version of the scenario foreground and background colors' do | |
| 7 | + scenario = users(:bob).scenarios.build(tag_fg_color: '#ffffff', tag_bg_color: '#000000') | |
| 8 | + style_colors(scenario).should == "color:#ffffff;background-color:#000000" | |
| 9 | + end | |
| 10 | + end | |
| 11 | + | |
| 12 | +end | 
| @@ -5,6 +5,15 @@ describe Scenario do | ||
| 5 | 5 |  | 
| 6 | 6 | it_behaves_like HasGuid | 
| 7 | 7 |  | 
| 8 | + describe "defaults" do | |
| 9 | + it "defaults the tag foreground color" do | |
| 10 | + new_instance.tag_fg_color.should == '#ffffff' | |
| 11 | + end | |
| 12 | + it "defaults the tag background color" do | |
| 13 | + new_instance.tag_bg_color.should == '#5bc0de' | |
| 14 | + end | |
| 15 | + end | |
| 16 | + | |
| 8 | 17 | describe "validations" do | 
| 9 | 18 | before do | 
| 10 | 19 | new_instance.should be_valid |